import dotenv from 'dotenv';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { generateService } from '@umijs/openapi';

import { customClassName, customFunctionName } from './util';

// 配置 dotenv
dotenv.config();

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const SERVER_URL = process.env.VITE_SERVER_URL;

generateService({
  schemaPath: `${SERVER_URL}app/v3/api-docs/bizApi`,
  projectName: 'bizApi',
  namespace: 'BIZAPI',
  serversPath: path.resolve(__dirname, '../../src/services'),
  templatesFolder: path.resolve(__dirname, './templates'),
  requestLibPath: "import { api } from '@/utils/api'",
  apiPrefix: `'/app'`,
  hook: {
    customClassName: customClassName.bind({}, 'base'),
    customFunctionName: customFunctionName
  }
});
